package converters;
  
import javax.faces.component.UIComponent;  
import javax.faces.context.FacesContext;  
import javax.faces.convert.Converter;  
import javax.faces.convert.FacesConverter;

import domain.DadServicesDAO;
  
@FacesConverter(value="serviceConverter")
public class ServiceConverter implements Converter {  
  
  
    public Object getAsObject(FacesContext facesContext, UIComponent component, String submittedValue) {  
    	DadServicesDAO s = null;
        try {
			if (submittedValue.trim().equals("")) {  
			    return null;  
			} else { 
				
				long oid = Long.parseLong(submittedValue);  
 
				s = new DadServicesDAO(oid, true, 0);
			       
			}
		} catch (NumberFormatException e) {
//			Do nothing
		}
        return s;
    }  
  
    public String getAsString(FacesContext facesContext, UIComponent component, Object value) {  
        if (value == null || value.equals("")) {  
            return "";  
        } else {  
            return String.valueOf(((DadServicesDAO) value).getOid());  
        }  
    }  
}  